//测试文档
//#include "util.hpp"
//#include "data.hpp"
#include "server.hpp"

void FileTest()//文件测设工具
{
    ctv::FileUtil("./www").CreateDiretory();//创建文件
    ctv::FileUtil("./www/index.html").SetContent("<html> </html>");//设置内容

    std::string body;
    ctv::FileUtil("./www/index.html").GetContent(&body);//将内容写入body中
    std::cout << body.c_str() << std::endl;//打印需谨慎
    //std::cout << "嘿嘿" << std::endl;

    std::cout << ctv::FileUtil("./www/index.html").Size() << std::endl;//字符串大小
}

void JsonTest()
{
    Json::Value val;
    val["姓名"] = "校长";
    val["年龄"] = 18;
    val["成绩"].append(77.1);
    val["成绩"].append(88.1);
    val["成绩"].append(99.1);

    std::string body;
    ctv::JsonUtil::Serialize(val, &body);
    std::cout << body << std::endl;

    Json::Value stu;
    ctv  ::JsonUtil::UnSerialize(body, &stu);
    std::cout << stu["姓名"].asString() << std::endl;
    std::cout << stu["年龄"].asString() << std::endl;
    for(auto &a : stu["成绩"])
    {
        std::cout << a.asFloat() << std::endl;
    }

}

void DataTest()
{
    ctv::TableVideo tb_video;
    Json::Value video;
    // video["name"] = "轻音少女";
    // video["info"] = "yyds-----on";
    // video["video"] = "/video/K-ON-.mp4";
    // video["image"] = "/image/K-ON-.jpg";

    //tb_video.Insert(video);
    //tb_video.Updata(2,video);

    //tb_video.SelectAll(&video);
    //tb_video.SelectOne(1, &video);
    //tb_video.SelsctLike("轻音", &video);
    tb_video.Delete(2);

    std::string body;
    ctv::JsonUtil::Serialize(video, &body);
    std::cout << body << std::endl;
}

void ServerTest()
{
    ctv::Server server(9090);
    server.RunModule();
}

int main()
{
    // FileTest();
    //JsonTest();
    //DataTest();

    ServerTest();
    return 0;
}
